﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MyOA.DAL;
using MyOA.Model;

namespace MyOA.BLL
{
    public class LeftPanelManage
    {
        LeftPanelService service = new LeftPanelService();

        IList<SysFun> sysFunList = null;

        public LeftPanelManage() { }

        /// <summary>
        /// 为这个类的sysFunList变量赋值 可共享数据 减少查数据库的次数
        /// </summary>
        /// <param name="loginId"></param>
        public LeftPanelManage(string loginId)
        {
            sysFunList = getSysFunByLoginId(loginId);
        }

        /// <summary>
        /// 根据登陆号获取权限信息集合
        /// </summary>
        /// <param name="loginId">登陆号</param>
        /// <returns>返回权限信息</returns>      
        private IList<SysFun> getSysFunByLoginId(string loginId)
        {
            return service.getSysFunByLoginId(loginId);
        }

        /// <summary>
        /// 根据登陆号获取主菜单
        /// </summary>
        /// <param name="loginId">登录号</param>
        /// <returns>返回主菜单名</returns>
        public IList<SysFun> getMainMenu()
        {
            //var sysFuns = getSysFunByLoginId(loginId);//内部方法

            //删选ParentNodeId为0的集合
            var mainMenus = from sysFun in sysFunList
                           where sysFun.ParentNodeId == 0
                           select sysFun;
           
            return mainMenus.ToList<SysFun>();
        }

        /// <summary>
        /// 根据主菜单ID获取子菜单集合
        /// </summary>
        /// <param name="mainMenuId">主菜单ID</param>
        /// <returns>返回子菜单集合</returns>
        public IList<SysFun> getChildrenMenusByMainMenuId(int mainMenuId)
        {
            var childrenMenus = from sysFun in sysFunList
                                where sysFun.ParentNodeId == mainMenuId
                                select sysFun;
            return childrenMenus.ToList<SysFun>();
        }
    }
}
